import ButtonImage from '@/assets/draw-tip.png'
import ButtonImageDSL from '@/assets/draw-tip-dsl.png'
import ButtonImageElm from '@/assets/draw-tip-elm.png'
import ButtonImageGJ from '@/assets/draw-tip-gj.png'
import ButtonImageLBX from '@/assets/draw-tip-lbx.png'
import ButtonImageYF from '@/assets/draw-tip-yf.png'

const ChannelConfig = {
  default: {
    logo: ButtonImage,
    link: 'https://mod10.ug.ele.me/wow/alsc/mod/c1474c7db25accb9ab49ddf3?targetUrl=eleme%3A%2F%2Fweb%3Furl%3Dhttps%253A%252F%252Ftb.ele.me%252Fwow%252Falsc%252Fmod%252F04e15efaf86d5e7dd0f021d3&isAutoCallapp=true',
  },
  lbx: {
    logo: ButtonImageLBX,
    link: 'https://m.lbxcn.com/?7Tv1bY4',
  },
  dsl: {
    logo: ButtonImageDSL,
    link: 'https://wx.dslyy.com/api/v1/mc-free/wx-applet/getUrlLinkV2?path=apps/o2o/main/pages/promotion-activity/index&query=7D3A396EB736DE4C2DF5A5CF5E51F400CF26BE87F9C6000528F5D3DA548AE5F4B2F1E3B52AE1304CE09700704C3FD4A72EC27EAAB6D9A51C6BBF909D93E5D40309803355D31017FF428A5A8B1F1CF4DF0DDE4EA765F484EAA315BF51CADB73512D191D929C329AC7FF5253FF800EDF3FE36187C980CF75E13818BEB38856BC58',
  },
  yf: {
    logo: ButtonImageYF,
    link: 'https://market.waimai.meituan.com/gd2/wm/3CTV7T?tenant=medicine&isMultiTab=true&bs=0000&',
  },
  gj: {
    logo: ButtonImageGJ,
    link: 'https://market.waimai.meituan.com/gd2/wm/XG1YmO?tenant=medicine&isMultiTab=true&bs=0000&utm_source=mtmed_brandtf',
  },
  elm: {
    logo: ButtonImageElm,
    link: 'https://tb.ele.me/wow/alsc/mod/6ff2ce69dc3047166de70f05',
  },
}

export default function MallLinkButton({
  defaultLogo = false,
}: {
  defaultLogo?: boolean
}) {
  const channel = defaultLogo ? 'default' : (sessionStorage.getItem('channel') || 'default')
  const logo = ChannelConfig[channel as keyof typeof ChannelConfig]?.logo || ChannelConfig.default.logo
  const link = ChannelConfig[channel as keyof typeof ChannelConfig]?.link || ChannelConfig.default.link

  return (
    <img
      src={logo}
      onClick={async () => {
        window.location.href = link
      }}
      className="w-[280px] h-auto"
    />
  )
}

MallLinkButton.defaultProps = {
  animate: true,
}
